package com.qtyx.nms.ui.adapter

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.ldd.base.ui.adapter.BaseRVAdapter
import com.ldd.base.ui.adapter.BaseRVVH
import com.qtyx.nms.R
import com.qtyx.nms.mvp.model.bean.MessageBean

/**
 * 消息适配器
 */
class MessageAdapter(mContext: Context, list: List<MessageBean.Data>) :BaseRVAdapter<MessageBean.Data>(mContext, list) {
    override fun getLayoutId(viewType: Int)= R.layout.item_message

    var selectPosition=-1

    override fun convert(vh: BaseRVVH, position: Int, data: MessageBean.Data) {
        val llMain=vh.getView<LinearLayout>(R.id.ll_item_message_main)
        val viewLine=vh.getView<View>(R.id.view_item_message_line)
        val tvTitle=vh.getView<TextView>(R.id.tv_item_message_title)

        if(0==position){
            viewLine.visibility=View.GONE
        }else{
            viewLine.visibility=View.VISIBLE
        }
        tvTitle.text=data.noticeHead

        //当前选中，更改背景色
        if(position==selectPosition){
            llMain.setBackgroundColor(mContext.resources.getColor(R.color.message_list_select_bg))
        }else{
            llMain.setBackgroundColor(mContext.resources.getColor(R.color.message_list_no_select_bg))
        }


        llMain.setOnClickListener{
            selectPosition=position
            notifyDataSetChanged()

            onItemClickListener?.onItemClick(position,data)
        }
    }

    var onItemClickListener: OnItemClickListener? = null

    interface OnItemClickListener {
        fun onItemClick(position: Int,data: MessageBean.Data)
    }


}